package com.qf.tms.controller;


import com.qf.tms.entity.Student;
import com.qf.tms.entity.StudentVO;
import com.qf.tms.entity.Subjects;
import com.qf.tms.entity.SubjectsVO;
import com.qf.tms.service.StudentService;
import com.qf.tms.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.Subject;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "stu接口")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping("/stu/addMore")
    @ApiOperation(value = "批量添加学生")
    public R addStuMore(@RequestBody List<Student> studentList) {
        int temp = studentService.addStuMore(studentList);
        if (temp > 0) {
            return R.success(2000);
        }else {
            return R.fail();
        }
    }

    @GetMapping("/stu/add")
    @ApiOperation(value = "添加单个学生")
    public R addStu(Student student) {
        int i = studentService.addStu(student);
        if (i > 0) {
            return R.success(2000);
        }else {
            return R.fail();
        }

    }
    @GetMapping("/stu/delete/{id}")
    @ApiOperation(value = "根据id删除学生")
    public R deleteStu(@PathVariable int id) {
        int i = studentService.deleteStuById(id);
        if (i > 0) {
            return R.success(2000);
        }else {
            return R.fail();
        }
    }

    @GetMapping("/stu/delete/more")
    @ApiOperation(value = "根据id删除多个学生")
    public R deleteStuMore(@RequestParam List<Integer> ids){
        int i = studentService.deleteStuByIdMore(ids);
        if (i > 0) {
            return R.success(2000);
        }else {
            return R.fail();
        }
    }

    @GetMapping("/stu/update")
    @ApiOperation(value = "id动态更新")
    public R updateStuById(Student student) {
        int i = studentService.updateStuById(student);
        if (i > 0) {
            return R.success(2000);
        }else  {
            return R.fail();
        }
    }

    @GetMapping("/stu/select")
    @ApiOperation(value = "查询全部")
    public R selectStuById() {
        List<Student> stuList= studentService.select();
        if (stuList !=null) {
            return R.success(stuList);
        }else  {
            return R.fail();
        }

    }

    @GetMapping("/stu/select/{id}")
    @ApiOperation(value = "id查询")
    public R selectStuById(@PathVariable int id) {
        List<Student> stuList= studentService.selectStuById(id);
        if (stuList !=null) {
            return R.success(stuList);
        }else  {
            return R.fail();
        }

    }

    @GetMapping("/stu/select/more")
    @ApiOperation(value = "id模糊查询")
    public R selectStu(@RequestParam Map<String, String> map) {
        List<Student> stuList= studentService.selectStu(map);
        if (stuList !=null) {
            return R.success(stuList);
        }else  {
            return R.fail();
        }

    }


    @GetMapping("/stu/select/stu&classroom")
    @ApiOperation(value = "查询所有学生信息及对应的班级信息")
    public R selectStuAndClassroomAll() {
        List<StudentVO> stuVOList = studentService.selectStuAndCmAll();
        if (stuVOList != null) {
            return R.success(stuVOList);
        }else {
            return R.fail();
        }
    }

    @GetMapping("/stu/select/subject/{stuId}")
    @ApiOperation(value = "查询一个学生信息以及所学习的所有学科信息")
    public R selectStuSubject(@PathVariable int stuId) {
        List<Subjects> stuSubList = studentService.selectStuSubject(stuId);
        if (stuSubList != null) {
            System.out.println(stuSubList);
            return R.success(stuSubList);
        }else  {
            return R.fail();
        }
    }

    @GetMapping("/stu/select/subject&teacher/{stuId}")
    @ApiOperation(value = "查询一个学生信息以及所学习的所有学科信息,以及每个学科关联的老师信息")
    public R selectStuSubjectAndTeacher(@PathVariable int stuId) {
        List<StudentVO> stuSubList = studentService.selectStuSubAndTeacher(stuId);
        if (stuSubList != null) {
            System.out.println(stuSubList);
            return R.success(stuSubList);
        }else  {
            return R.fail();
        }
    }

    @GetMapping("/stu/subject/stu&all/{stuId}")
    @ApiOperation(value ="查询学生的全部学习科目")
    public R findStuSubjectAll(@PathVariable int stuId) {
        List<Subjects> subjects = studentService.findStuSubjectAll(stuId);
        if (subjects != null) {
            return R.success(subjects);
        }else   {
            return R.fail();
        }
    }

    @GetMapping("/stu/subject/{subId}")
    @ApiOperation(value ="根据科目id茶学科目名称")
    public R findSubjectById(@PathVariable int subId) {
        Subjects subject = studentService.findSubjectById(subId);
        if (subject !=null) {
            return R.success(subject);
        }else  {
            return R.fail();
        }
    }

}
